var httpTool = require('../../utils/network.js');
var util = require('../../utils/util.js')
//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    bannerList: [],
    schoolList: [],
    articleList: [],
    voteList: [],
    yearCount: '',//季次
    schoolCount: '',//院校
    studentCount: '',//大学生
    commentList: [{
      isHide: true
    }, {
      isHide: true
    }]
  },
  //我的动态
  toMyFeed: function () {
    util.navigateTo('../myfeed/myfeed');
  },
  
  toEnroll: function () {
    util.navigateTo('/pages/toEnroll/toEnroll')
  },
  toYmjq:function(){
    util.navigateTo( '/pages/perfectholiday/perfectholiday')
  },
  toQgjx: function () {
    util.navigateTo('/pages/workstudy/workstudy')
  },
  toDeveloping: function () {
    // util.fxAlert('开发小伙伴正在开发中，敬请期待!')
    // return;
  },
  /**
   * 获取圆满假期信息并保存到全局应用中
   */
  getPerfectHolidayInfo: function () {
    var that = this;
    var url = app.data.httpUrl + 'v1/vacation/getVacationInfo'
    httpTool.sendRequest(url, {}, '', function (res) {
      app.globalData.vacationInfo = res.entity;
      console.log("vacationInfo:");
      console.log(res.entity)
    }, function (error) {
      console.log("加载圆满假期信息异常:", error);
    })
  },
  /**
   * 获取学校列表
   */
  getSchoolList:function(){
    var that = this;
    var url = app.data.httpUrl + 'v1/index/getTopSchoolList'
    httpTool.sendRequest(url, {}, '', function (res) {
      that.setData({
        schoolList:res.list
      })
      console.log("schoolList:");
      console.log(res.list)
    }, function (error) {
      console.log("加载学校列表异常:", error);
    })
  },
  getArticleList: function () {
    var that = this;
    var url = app.data.httpUrl + 'v1/index/getTopMediaArticleInfoList'
    httpTool.sendRequest(url, {}, '', function (res) {
      that.setData({
        articleList: res.list
      })
      console.log("articleList:");
      console.log(res.list)
    }, function (error) {
      console.log("加载文章列表异常:", error);
    })
  },
  getVoteList: function () {
    var that = this;
    var url = app.data.httpUrl + 'v1/index/getTopVotePlayerList'
    httpTool.sendRequest(url, {}, '', function (res) {
      that.setData({
        voteList: res.list
      })
      console.log("voteList:");
      console.log(res.list)
    }, function (error) {
      console.log("加载投票列表异常:", error);
    })
  },
  getBannerList: function () {
    var that = this;
    var url = app.data.httpUrl + 'v1/index/getTopBannerList'
    httpTool.sendRequest(url, {}, '', function (res) {
      that.setData({
        bannerList: res.list
      })
      console.log("bannerList:");
      console.log(res.list)
    }, function (error) {
      console.log("加载轮播图异常:", error);
    })
  },
  // 弹出、隐藏评论框
  toggleComment: function(e) {
    let _index = e.currentTarget.dataset.index;
    this.data.commentList.forEach((item, index) => {
      let _key = 'commentList[' + index + '].isHide'
      this.setData({
        [_key]: _index == index ? !this.data.commentList[_index].isHide : true
      })
    })
  },
  // 划入空白区域隐藏评论框
  hideAllComment: function() {
    let _isRun = this.data.commentList.some((item) => {
      return !item.isHide
    })
    _isRun && this.data.commentList.forEach((item, index) => {
      let _key = 'commentList[' + index + '].isHide'
      this.setData({
        [_key]: true
      })
    })
  },
  dianZan: function() {
    console.log("点赞")
  },
  pingLun: function() {
    console.log("评论")
  },
  fenXiang: function() {
    console.log("分享")
  },
  onLoad: function(options) {
    // 生命周期函数--监听页面加载
    this.setData({
      yearCount: app.globalData.yearCount,//季次
      schoolCount: app.globalData.schoolCount,//院校
      studentCount: app.globalData.studentCount,//大学生
    })
    //轮播图
    this.getBannerList();
    //学校列表
    this.getSchoolList();
    //文章列表
    this.getArticleList();
    //投票列表
    this.getVoteList();
    //获得圆满假期信息
    this.getPerfectHolidayInfo();

  },
  onReady: function() {
    // 生命周期函数--监听页面初次渲染完成

  },
  onShow: function() {
    // 生命周期函数--监听页面显示

  },
  onHide: function() {
    // 生命周期函数--监听页面隐藏

  },
  onUnload: function() {
    // 生命周期函数--监听页面卸载

  },
  onPullDownRefresh: function() {
    // 页面相关事件处理函数--监听用户下拉动作

  },
  onReachBottom: function() {
    // 页面上拉触底事件的处理函数

  },
  onShareAppMessage: function() {
    // 用户点击右上角分享
    return {
      title: 'title', // 分享标题
      desc: 'desc', // 分享描述
      path: 'path' // 分享路径
    }
  }
})